﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Collections;
using Dala.Samples.DataAccessLayer;

namespace Dala.Samples.DataAccessLayer
{
	public partial class DalaDataSource
	{
				private List<Product> _Products;
		public List<Product> GetAllProducts()
        {
		    if(System.Web.HttpContext.Current.Session!=null && System.Web.HttpContext.Current.Session["_QPRO_Product"]!=null)
			{
				_Products=System.Web.HttpContext.Current.Session["_QPRO_Product"] as List<Product>;
			}
			
			if(_Products!=null)
			{
				return _Products;
			}
			_Products= Product.GenerateProductCollectionFromReader(DataSet.Tables["Product"].CreateDataReader());
			
			if(System.Web.HttpContext.Current.Session!=null)
			{			
				System.Web.HttpContext.Current.Session["_QPRO_Product"]=_Products;
			}
			return _Products;
				
			
        }//end method

		public void DeleteProduct(Product toDel)
		{
			_Products=System.Web.HttpContext.Current.Session["_QPRO_Product"] as List<Product>;
			if(_Products!=null)
			{
				_Products.Remove(toDel);
				System.Web.HttpContext.Current.Session["_QPRO_Product"]=_Products;
			}
			else
			{
				_Products= Product.GenerateProductCollectionFromReader(DataSet.Tables["Product"].CreateDataReader());
				_Products.Remove(toDel);
				System.Web.HttpContext.Current.Session["_QPRO_Product"]=_Products;
				
			}
		}
				private List<Location> _Locations;
		public List<Location> GetAllLocations()
        {
		    if(System.Web.HttpContext.Current.Session!=null && System.Web.HttpContext.Current.Session["_QPRO_Location"]!=null)
			{
				_Locations=System.Web.HttpContext.Current.Session["_QPRO_Location"] as List<Location>;
			}
			
			if(_Locations!=null)
			{
				return _Locations;
			}
			_Locations= Location.GenerateLocationCollectionFromReader(DataSet.Tables["Location"].CreateDataReader());
			
			if(System.Web.HttpContext.Current.Session!=null)
			{			
				System.Web.HttpContext.Current.Session["_QPRO_Location"]=_Locations;
			}
			return _Locations;
				
			
        }//end method

		public void DeleteLocation(Location toDel)
		{
			_Locations=System.Web.HttpContext.Current.Session["_QPRO_Location"] as List<Location>;
			if(_Locations!=null)
			{
				_Locations.Remove(toDel);
				System.Web.HttpContext.Current.Session["_QPRO_Location"]=_Locations;
			}
			else
			{
				_Locations= Location.GenerateLocationCollectionFromReader(DataSet.Tables["Location"].CreateDataReader());
				_Locations.Remove(toDel);
				System.Web.HttpContext.Current.Session["_QPRO_Location"]=_Locations;
				
			}
		}
		
	}//end of class
}//end of namespace 


